<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/15
 * Time: 9:03
 */
session_start();

function getLoginStatus(){

    //是否有token COOKIES值
    if(empty($_COOKIE['Token'])){
        return false;
    }
    $token = $_COOKIE['Token'];
    //判断是否SESSION中是否有对于的token项
    if(empty($_SESSION[$token])){
        return false;
    }
    return true;
}

/**
 * @param $type 类型 （1存钱 ，2 取钱）
 * @param $cardId
 * @param $money
 */
function changeMoney($type,$cardId,$money){

 $c_money=0;
 $inMoney=0;
 $outMoney=0;

 if($type==1){
     $c_money=$money;
     $inMoney=$money;
     $outMoney=0;
 }else{
     $c_money=-$money;
     $inMoney=0;
     $outMoney=$money;
 }

 //sql语句

    $sql = "update bankcard set CardMoney=CardMoney+ $c_money where CardId=".$cardId;

 if($type==2){
     $sql .=" and CardMoney>=$money";
 }
    $result = DbTools::noSelect($sql);
    if(!$result['status']){
        return $result;
    }
// 添加日志
    $Sql = "insert into cardexchange(CardId,MoneyInBank,MoneyOutBank,ExchangeTime) 
          values($cardId,$inMoney,$outMoney,NOW())";
    $result = DbTools::noSelect($Sql);

    return $result;
}
//获取转账卡号CardId

function getByCardId($id){
    $sql="select * from bankcard where CardNo= ".$id;
    $result =DbTools::select($sql);
    return $result[0]['CardId'];
}
//转账记录日志
function tran($b_CardId,$z_CardId,$money){
    $sql="insert into cardtransfer(CardIdOut,CardIdIn,TransferMoney,TransferTime)  values($b_CardId,$z_CardId,$money,now()) ";
    $result = DbTools::noSelect($sql);
    return $result;
}
function allCardId($AccountId,$CardNo){
    $sql="select CardNo,CardMoney from bankcard where  AccountId= $AccountId and CardNo != $CardNo and CardState=0";


    $result =DbTools::select($sql);

    return $result;
}


function changeState($cardNo){

   $sql="update  bankcard set CardState =-1 where CardNo= $cardNo";
    $result =DbTools::noSelect($sql);
    return $result;
}


